package cn.wsalix.user.service.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.anlaser.service.impl.CommonServiceImpl;
import cn.anlaser.utils.SearchFilter;
import cn.anlaser.utils.SearchFilter.Operator;
import cn.wsalix.user.entity.Favorite;
import cn.wsalix.user.form.FavoriteForm;
import cn.wsalix.user.repository.FavoriteRepository;
import cn.wsalix.user.service.FavoriteService;

@Service("favoriteService")
public class FavoriteServiceImpl extends
		CommonServiceImpl<FavoriteForm, FavoriteRepository, Favorite> implements
		FavoriteService {
	@Autowired
	private FavoriteRepository favoriteRepository;

	@Override
	public String module() {
		return "/user/favorite";
	}

	@Override
	public FavoriteRepository getRepository() {
		return favoriteRepository;
	}

	@Override
	public Class<Favorite> getEntityClazz() {
		return Favorite.class;
	}

	@Override
	public Map<String, SearchFilter> buildByForm(FavoriteForm form) {
		Map<String, SearchFilter> filters = buildFilter(form);
		if (form.getUserId() != null && form.getUserId() != 0) {
			filters.put("userId",
					new SearchFilter("userId", Operator.EQ, form.getUserId()));
		}
		if (form.getType() != null) {
			filters.put("type",
					new SearchFilter("type", Operator.EQ, form.getUserId()));
		}
		if (form.getFkId() != null && form.getFkId() != 0) {
			filters.put("fkId",
					new SearchFilter("fkId", Operator.EQ, form.getFkId()));
		}

		return filters;
	}
}
